use std::io;
use std::cmp::Ordering;
use rand::Rng;

fn main() {
    println!("Угадай число!");
    
    let secret_number = rand::thread_rng().gen_range(1..=100);
    
    loop {
        println!("Вводи свое число!");

        let mut guess = String::new();
    
        io::stdin()
            .read_line(&mut guess)
            .expect("Не похоже на число от 0 до 100");
        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };
        println!("Твое число: {guess}");

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Мало!"),
            Ordering::Greater => println!("Много!"),
            Ordering::Equal => {
                println!("Угадал!");
                break;
            }
        }
    }
}
